<?php

if (!defined('BASEPATH'))
  exit('No direct script access allowed');

/**
 * Trieda na upload suborov
 * 
 * @author Marek Letavay 
 */
class Upload extends CI_Controller {

  function __construct() {
    parent::__construct();
    if (!isLogged())
      redirect('login');
    $this->load->library('form_validation');
  }

  function index() {
    $this->template->set('title', 'SKaP - upload');
    $data["mess"] = "Upload súborov";
    $this->template->view("upload_form", $data);
  }

  /**
   * Metoda na uploadovanie suboru na server
   * 
   * @param type $path subor na uploadovanie
   * @return  
   */
  function do_upload() {
    $config['upload_path'] = './temp/';
    $config['allowed_types'] = '*';

    $this->load->library('upload', $config);
    if (!$this->upload->do_upload()) {
      $error = array("error" => $this->upload->display_errors());
      return $error;
    } else {
      $result = $this->upload->data();
      if (($result["file_ext"] == ".ics") || ($result["file_ext"] == ".xml")) {
        return $this->upload->data();
      } else {
        $error = array("error" => "Zlý formát súboru");
        return $error;
      }
    }
  }

}

?>
